<?php
namespace app\admin\controller;

use think\Env;

class {subFolder}Controller extends Base
{

[folder start]
    /*****************************************************
     * [tblTitle]模快
     *****************************************************/
   //获取
    public function {tblName}View()
    {
        $id=request()->post("id");
        if($id==0){
            //表单初始值
            $data["id"]=0;
            //$data["status"]=1;
            $this->success($data);
        }

        $model =db('{tblName}')->where("id",$id)->find();
        if($model){
            $this->success($model);
        }else{
            $this->error("记录获取失败");
        }
    }

    //列表查询
    public function {tblName}list()
    {
        if(request()->isPost()){
            $post = request()->post();
            $pagesize=request()->post("pagesize");
            $pageindex=request()->post("pageindex");

            //查询条件
            $str_where = "1=1";
            if(!empty($post["username"])){
                $str_where.=" and username like '%".$post["username"]."%'";
            }
            //echo $str_where;exit();

            //分页总数
            $total=db("{tblName}")->where($str_where)->count();
            $data["total"]=$total;

            //数据列表
            $rows=db("{tblName}")->where($str_where)->page($pageindex,$pagesize)->select();
            $data["rows"]=$rows;
            $this->success($data);
        }
        return view();
    }

 
    //添加
    public function {tblName}add()
    {
        if (request()->isPost()) {
            $post = request()->post();

            /*if(!$post["username"]){
                $this->error("用户名不能为空.");
            }*/
            if($post["id"]) {
				//修改保存
                db('{tblName}')->where("id",$post["id"])->update($post);
            }else{
				//添加保存
				//$post["addDate"]=date("Y-m-d H:i:s");
                db('{tblName}')->insert($post);
            }
            $this->success($post);
        }

        return view();
    }

    //删除
    public function  {tblName}delete()
    {
        $id=request()->post("id");
        if(!$id){
            $this->error("非法的参数");
        }
        $result=db('{tblName}')->delete($id);
        if($result === false){
            $this->error("删除失败");
        }else{
            $this->success($id);
        }
    }

[folder end]	
}
